<template>
<div>
    <div class="head">
        <p>序号</p>
        <p>操作</p>
        <p>时间</p>
    </div>
    <div class="main">
        <p v-for="(item, index) in logs" :key="index">
            <span>{{ index + 1 }}</span>
            <span>{{ item.add }}</span>
            <span>{{ item.create_time }}</span>
        </p>
    </div>
</div>
</template>

<script>
import { formatTime, formatTimeSimple } from "@/utils/index.js";
export default {
    data() {
        return {
            logs: [],
        };
    },
    components: {},
    mounted() {
        console.log("log页面的mounted....");
    },

    methods: {},
    onLoad() {
        console.log("log页面的onLoad....");
    },
    onShow() {
        console.log("log页面的onShow....");
        const userinfo = wx.getStorageSync("userinfo");
        if (!userinfo.openid) {
            wx.switchTab({
                url: "/pages/me/main",
            });
        } else {
            const that = this;
            wx.cloud.callFunction({
                name: "getLogs",
                data: {
                    openid: userinfo.openid,
                },
                success: (res) => {
                    console.info("getLogs调用成功", res);
                    that.logs = res.result.data;
                    that.logs.forEach((item, index) => {
                        that.logs[index].create_time = formatTimeSimple(
                            new Date(item.date)
                        );
                    });
                    console.info("that.logs", that.logs);
                },
                fail: (res) => {
                    console.info("getLogs调用失败", res);
                },
            });
        }
    },
    onPullDownRefresh() {
        console.info("用户下拉刷新...onPullDownRefresh");
    },
    onReachBottom() {
        console.info("用户上拉触底事件....onReachBottom");
    },
    onShareAppMessage() {
        console.info("用户点击右上角分享按钮....onShareAppMessage");
    },
};
</script>

<style scoped>
p {
    padding: 0;
    margin: 0;
}

.head {
    width: 100%;
    height: 30px;
    border: 0px solid red;
    background-color: #ea5149;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    color: #ffffff;
    position: absolute;
    top: 0;
    left: 0;
}

.main {
    width: 100%;
    margin-top: 35px;
    border: 0px solid purple;
}

.main p {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
}
</style>
